package com.ysd.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.ysd.entity.News;
import com.ysd.impl.NewsDaolmpl;
import com.ysd.utli.BaseServlet;
import com.ysd.utli.Result;

public class AdminNewsServlet extends BaseServlet {
//查询新闻资讯
	public void getNew(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// localhost:8080/dayixiangmu/adminNews?reqName=getNew&newsCategoryid=1

		int nId = Integer.parseInt(request.getParameter("newsCategoryid"));
		NewsDaolmpl ns = new NewsDaolmpl();
		List<News> List = ns.getNewsList(nId);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		Gson gson = new Gson();
		String res = gson.toJson(List);
		out.print(res);

		out.flush();
		out.close();
	}
/**
 * 删除新闻资讯
 *  localhost:8080/dayixiangmu/adminNews?reqName=delNew
 */
	public void delNew(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// localhost:8080/dayixiangmu/adminNews?reqName=getNew&newsCategoryid=1

		int nsId = Integer.parseInt(request.getParameter("newsid"));
		NewsDaolmpl ns = new NewsDaolmpl();
		int n=ns.deleteNewsId(nsId);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		if (n>0) {
			out.print(Result.toClient(true, "删除成功", ""));
		} else {
			out.print(Result.toClient(false, "删除失败", ""));
		}
		out.flush();
		out.close();
	
	}
	
}
